package com.qcby.mybatis01.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
/**
 * 链接数据库
 * @author Administrator
 *
 */
public class DBConnection {
	// 数据库驱动类型
	String driver = "com.mysql.jdbc.Driver";
	// 数据库连接
    String url= "jdbc:mysql://localhost:3306/qcby_temp?useUnicode=true&characterEncoding=utf-8";
    // 数据账号
    String user = "root";
    // 密码
    String password = "";
    
    public Connection conn;

    public DBConnection() {

        try {
            // 反射获取驱动
        	Class.forName(driver);
            // 获取数据库连接
            conn = (Connection) DriverManager.getConnection(url, user, password);
            
            if(!conn.isClosed())
            	// 链接成功了！
                System.out.println("Succeeded connecting to the Database!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void close() {
        try {
            this.conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
